<template>
  <div id="app">
    <header class="main-header">
      <div class="header-left">
        <img src="@/assets/logo/logo.svg" alt="Logo" class="logo" />
        <h1 @click="redirectPage('/')" class="nav-title">团建预约系统</h1>
      </div>
      <el-menu
        :collapse="isCollapsed"
        :router="true"
        mode="horizontal"
        class="nav-menu"
        background-color="#2c3e50"
        text-color="#fff"
        active-text-color="#409EFF"
      >
        <el-menu-item index="/venues">
          <i class="el-icon-location"></i>
          <span>场地预约</span>
        </el-menu-item>
        <el-menu-item index="/activities">
          <i class="el-icon-date"></i>
          <span>活动管理</span>
        </el-menu-item>
        <el-menu-item index="/notifications">
          <i class="el-icon-bell"></i>
          <el-badge style="margin-top: -5px" v-show="notifications.length!==0"  :value="notifications.length" class="notification-badge">

          </el-badge>

          <span>消息通知</span>

        </el-menu-item>
      </el-menu>
      <div class="header-right">
<!--        <el-badge v-show="notifications.length!==0"  :value="notifications.length" class="notification-badge">-->
<!--          <i class="el-icon-bell"></i>-->
<!--        </el-badge>-->
        <el-dropdown @command="curDrop">
            <span class="user-dropdown" >
<!--              <img src="@/assets/avatar.svg" alt="Avatar" class="avatar" />-->
              <span>{{ username }}</span>
              <i class="el-icon-arrow-down"></i>
            </span>
          <el-dropdown-menu slot="dropdown" >
            <el-dropdown-item command="info" >信息管理</el-dropdown-item>
            <el-dropdown-item command="logout">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </header>
    <main class="main-content">
      <div class="breadcrumb-container">

        <!--        <el-breadcrumb separator="/">-->
        <!--          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>-->
        <!--          <el-breadcrumb-item>{{ currentRoute }}</el-breadcrumb-item>-->
        <!--        </el-breadcrumb>-->

        <div class="page-container">
          <transition name="fade-transform" mode="out-in">
            <router-view />
          </transition>
        </div>
      </div>
    </main>
  </div>
</template>

<script>
import router from "@/router";
import {getAllNotification} from "@/api/reunion/notification";
import redirect from "@/views/redirect.vue";
import {getInfo} from "@/api/login";
import Cookies from "js-cookie";

export default {
  name: 'App',
  data() {
    return {
      username:'',
      timer: null,
      notifications:[],
      isCollapsed: false
    }
  },
  computed: {
    currentRoute() {
      return this.$route.name || '首页'
    }
  },
  created() {
    this.getUserInfo()
    this.timer = setInterval(() => {
      this.getAllNotification()
    }, 10000)
  },
  beforeDestroy() {
    if (this.timer) {
      clearInterval(this.timer)
      this.timer = null
    }
  },
  methods: {
    getUserInfo(){
      this.username=Cookies.get('username')
      console.log(Cookies.get('username'))
    },
    curDrop(data){
      if (data==='logout'){
        this.$confirm('您确定要退出登录吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$store.dispatch('LogOut').then(() => {
            location.href = '/login';
          })
        }).catch(() => {
          // 取消
        })
      }
      if (data==='info'){
        location.href = '/index';
      }
      console.log(data)
    },
    getAllNotification(){
      getAllNotification().then(res => {
        this.notifications = res.data
        this.notifications=this.notifications.filter(n => n.status===0)
      })
    },
    redirectPage(path){
      this.$router.push({path:path})
    },
    router() {
      return router
    },
    toggleCollapse() {
      this.isCollapsed = !this.isCollapsed
    }
  }
}
</script>

<style lang="scss" scoped>
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700&display=swap');

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

#app {
  font-family: 'Noto Sans SC', sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: #f5f7fa;
}

.main-header {
  height: 60px;
  background-color: #2c3e50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  color: white;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;

  .logo {
    width: 32px;
    height: 32px;
  }

  .nav-title {
    font-size: 18px;
    font-weight: 500;
    color: white;
    margin: 0;
  }
}

.nav-menu {
  flex: 1;
  margin: 0 40px;
  border: none;
  background-color: transparent !important;

  .el-menu-item {
    height: 60px;
    line-height: 60px;

    &:hover, &:focus {
      background-color: rgba(255,255,255,0.1) !important;
    }
  }
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;

  .notification-badge {
    cursor: pointer;
    font-size: 20px;
    color: white;

    &:hover {
      color: #409EFF;
    }
  }
}

.user-dropdown {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: white;

  .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
  }
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: #f5f7fa;
}

.breadcrumb-container {
  padding: 16px 20px;
  background-color: white;
  border-bottom: 1px solid #e6e6e6;
  width: 100%;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 20px;

  .notification-badge {
    cursor: pointer;
    font-size: 20px;
    color: #606266;

    &:hover {
      color: #409EFF;
    }
  }

  .user-dropdown {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;

    .avatar {
      width: 32px;
      height: 32px;
      border-radius: 50%;
    }
  }
}

.page-container {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  width: 100%;
  height: calc(100vh - 120px);
}

// 过渡动画
.fade-transform-enter-active,
.fade-transform-leave-active {
  transition: all 0.5s;
}

.fade-transform-enter {
  opacity: 0;
  transform: translateX(-30px);
}

.fade-transform-leave-to {
  opacity: 0;
  transform: translateX(30px);
}
</style>

